import jwt from 'jsonwebtoken'
import { secrect } from './app'
const verify = (ctx,next) => {
    // ctx.body = 'verify 离场了'
    const token = ctx.request.headers['authorization']
    console.log(token);
    // console.log("verify 离场了");
    if(token) {
        ctx.body = {
            code: 401,
            message: '请登录'
        }
    }

    try {
        const payload = jwt.verify(token, secrect)
        ctx.user = payload
        next()

    } catch(err) {
        ctx.body = {
            code: 500,
            message: "过期了"
        }
    }
}

export default verify